package overall.webPackage
{
	import flash.events.EventDispatcher;
	import flash.utils.ByteArray;
	
	import overall.event.ServerDataEvent;
	
	import xnet.Message.ISokcetMessage;
	import xnet.Message.MessageBase;
	import xnet.core.ObjectUtils;

	public class WebDataManager extends EventDispatcher
	{
		public function WebDataManager()
		{
		}
		static private var _instance:WebDataManager;
		static public function get instance():WebDataManager{
			_instance=_instance||new WebDataManager;
			return _instance;
		}
		/**
		 *注入执行处理函数 
		 */		
		private  var _handler:Function
		public  function set handler(h:Function):void{
			_handler=h;
		}
		public function dataCom(pkg:ByteArray):void{
			var messageBase:MessageBase
			var copyByteArray:Object = ObjectUtils.copy(pkg);
			var cmd:int = ByteArray(copyByteArray).readUnsignedByte();
			messageBase=_handler(cmd,messageBase);
			messageBase.decodeSocketData(pkg)
			WebDataManager.instance.dispatchEvent(new ServerDataEvent(ServerDataEvent.ServerDataCom,messageBase))
		}
		
	}
}